<template>
  <div>
    <h1>用户参团列表</h1>
    <!-- 搜索 -->
    <div>
      <el-form :inline="true" :model="searchForm" class="demo-form-inline">
        <el-form-item label="状态">
          <el-select
            v-model="searchForm.statusId"
            placeholder="请选择状态"
            style="width: 200px"
            clearable
          >
            <el-option label="未开始" :value="0" />
            <el-option label="正在拼团" :value="1" />
            <el-option label="成功拼团" :value="2" />
            <el-option label="拼团失败" :value="3" />
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="loadList">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div>
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column prop="groupId" label="ID" />
        <el-table-column prop="joinName" label="活动名称" />
        <el-table-column prop="teamHeader" label="团长" />
        <el-table-column prop="teamLimit" label="成团人数" />
        <el-table-column prop="joinNum" label="参团人数" />
        <el-table-column prop="beginTime" label="开团时间" />
        <el-table-column prop="endTime" label="截止时间" />
        <el-table-column prop="groupStatus" label="拼团状态">
          <template #default="scope">
            <span v-if="scope.row.groupStatus == 0">未开始</span>
            <span v-if="scope.row.groupStatus == 1">正在拼团</span>
            <span v-if="scope.row.groupStatus == 2">成功拼团</span>
            <span v-if="scope.row.groupStatus == 3">拼团失败</span>
          </template>
        </el-table-column>
        <el-table-column prop="createBy" label="创建人" />
        <el-table-column prop="createTime" label="注册时间" />
        <el-table-column label="操作">
          <el-button type="primary">详情</el-button>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div style="margin-top: 20px">
      <div class="demo-pagination-block" style="width: 800px; margin: 0 auto">
        <el-pagination
          v-model:current-page="searchForm.pageNum"
          v-model:page-size="searchForm.pageSize"
          :page-sizes="[1, 2, 4, 6, 8]"
          :background="true"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from "vue";
import { getGroupList } from "../api/api";

const tableData = ref([]);
const total = ref(0);
const searchForm = ref({
  statusId: null,
  pageNum: 1,
  pageSize: 1,
});

//分页
const handleSizeChange = (val: number) => {
  console.log(`${val} items per page`);
  searchForm.value.pageSize = val;
  loadList();
};
const handleCurrentChange = (val: number) => {
  console.log(`current page: ${val}`);
  searchForm.value.pageNum = val;
  loadList();
};
const loadList = () => {
  getGroupList(searchForm.value).then((res) => {
    if (res.data.code == 200) {
      tableData.value = res.data.data.records;
      total.value = res.data.data.total;
    }
  });
};
onMounted(() => {
  loadList();
});
</script>

<!-- 分页样式 -->
<style scoped>
.demo-pagination-block + .demo-pagination-block {
  margin-top: 10px;
}
.demo-pagination-block .demonstration {
  margin-bottom: 16px;
}
</style>
<!-- 条件搜索样式 -->
<style>
.demo-form-inline .el-input {
  --el-input-width: 220px;
}

.demo-form-inline .el-select {
  --el-select-width: 220px;
}
</style>
